/*--- 左侧菜单----*/
$(function() {
    $('#nav-accordion').dcAccordion({
        eventType: 'click',
        autoClose: true,
        saveState: true,
        disableLink: true,
        speed: 'slow',
        showCount: false,
        autoExpand: true,
//        cookie: 'dcjq-accordion-1',
        classExpand: 'dcjq-current-parent'
    });

    //  左侧菜单收缩 开关 toggle
    function responsiveView() {
        var wSize = $(window).width();
        if (wSize <= 768) {
            $('#container').addClass('sidebar-close');
            $('#sidebar > ul').hide();
        }

        if (wSize > 768) {
            $('#container').removeClass('sidebar-close');
            $('#sidebar > ul').show();
        }
    }
    $(window).on('load', responsiveView);
    $(window).on('resize', responsiveView);

    $(".wrapper").css("min-height",$(window).height()-60-34);

});

//    sidebar dropdown menu auto scrolling
    jQuery('#sidebar .sub-menu > a').click(function () {
        var o = ($(this).offset());
        diff = 250 - o.top;
        if(diff>0)
            $("#sidebar").scrollTo("-="+Math.abs(diff),500);
        else
            $("#sidebar").scrollTo("+="+Math.abs(diff),500);
    });


    $('.icon-reorder').click(function () {
        if ($('#sidebar > ul').is(":visible") === true) {
            $('#main-content').css({
                'margin-left': '0px'
            });
            $('#sidebar').css({
                'margin-left': '-210px'
            });
            $('#sidebar > ul').hide();
            $("#container").addClass("sidebar-closed");
        } else {
            $('#main-content').css({
                'margin-left': '210px'
            });
            $('#sidebar > ul').show();
            $('#sidebar').css({
                'margin-left': '0'
            });
            $("#container").removeClass("sidebar-closed");
        }
    });

// 自定义的滚动条样式和颜色 scrollbar
    $("#sidebar").niceScroll({styler:"fb",cursorcolor:"#ffda00", cursorwidth: '3', cursorborderradius: '10px', background: '#0091a9', spacebarenabled:false, cursorborder: ''});

    $("html").niceScroll({styler:"fb",cursorcolor:"#ffda00", cursorwidth: '6', cursorborderradius: '10px', background: '#0091a9', spacebarenabled:false,  cursorborder: '', zindex: '1000'});

//  panel 向上收缩的代码 

    jQuery('.panel .tools .icon-chevron-down').click(function () {
        var el = jQuery(this).parents(".panel").children(".panel-body");
        if (jQuery(this).hasClass("icon-chevron-down")) {
            jQuery(this).removeClass("icon-chevron-down").addClass("icon-chevron-up");
            el.slideUp(200);
        } else {
            jQuery(this).removeClass("icon-chevron-up").addClass("icon-chevron-down");
            el.slideDown(200);
        }
    });
//  panel 删除的代码
    jQuery('.panel .tools .icon-remove').click(function () {
        jQuery(this).parents(".panel").parent().remove();
    });
//    tool tips
    $('.tooltips').tooltip();
//    popovers
    $('.popovers').popover();



jQuery.loading ={  
    show : function(){  
        // var loaddiv = $("<div id='loading' style='text-align: center;display: block; position: absolute; top: 0%; left: 0%; width: 100%; height: 2000px; background-color: #FFF; opacity:0.50;z-index:9999;'><img style='margin: 220px auto 0 auto;' src='./images/loading.gif'><br><br>loading...</div>");

        $('<div id="system-loading" style="text-align: center;display: block; position: fixed; top: 0; left: 0;overflow: hidden;width: 100%; height: 1000px; background:url(\'./js/fancybox/fancybox_overlay.png\');z-index:4040;"><div style="background-image: url(\'./js/fancybox/fancybox_sprite2.png\');position: fixed;top: 50%;left: 50%;margin-top: -60px;margin-left: -60px;background-position: 0 0;opacity: 0.8;cursor: pointer;z-index: 8060;"><div style="width: 118px;height: 118px;background: url(\'./js/fancybox/fancybox_loading.gif\') center center no-repeat;"></div></div></div>').appendTo('body');

    },  

    hide : function(){  
        $('#system-loading').fadeOut(function(){
            $('#system-loading').remove();
        });
    }  
}  